/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Gautier
 */
public class SerializeContact {

    public static void output(ArrayList<Contact> a) {
        try {
            FileOutputStream fichier = new FileOutputStream("contacts.ser");
            ObjectOutputStream oos = new ObjectOutputStream(fichier);
            oos.writeObject(a);
            oos.flush();
            oos.close();
        } catch (java.io.IOException e) {
            System.out.println("Error in output");
        }
    }
    
    public static void input(ArrayList<Contact> a){
        FileInputStream fichier = null;
        try {
            fichier = new FileInputStream("contacts.ser");
            ObjectInputStream ois = new ObjectInputStream(fichier);
            ArrayList al;
            al = (ArrayList<Contact>) ois.readObject();
            a.removeAll(a);
            a.addAll(al);
            
        } catch (Exception ex) {
            System.out.println("Error in input");
        }        
    }
}
